<div class="login-wrap">
	<form class="gd-form" id="forgotForm">
		<div class="title">Forgot password</div>
		<div class="gd-form-item">
			<input class="gd-input" type="text" id="forgotEmail" placeholder="Email">
		</div>
		<div class="gd-form-item">
			<div class="gd-input-group">
				<input class="gd-input" type="text" id="forgotVerCode" placeholder="Verification code" maxlength="6" oninput="if(value.length>6)value=value.substring(0,6)">
				<div class="gd-input__append">
					<button class="gd-btn btn-info" id="codeBtn" type="button" onclick="sendForgotCode(this)">Aquire</button>
				</div>
			</div>
		</div>
		<div class="gd-form-item">
			<input class="gd-input" type="password" id="forgotPwd" placeholder="Password(min 6 characters)" maxlength="20" oninput="if(value.length>20)value=value.substring(0,20)">
		</div>
		<div class="gd-form-item">
			<button type="button" class="gd-btn btn-info" onclick="forgotSubmit()">Submit</button>
		</div>
	</form>
</div>
<script>
	function sendForgotCode(btn) {
        let email = document.getElementById('forgotEmail').value
        if(!email || !checkEmail(email)) {
            showToast('please check Email')
            return false
        }
		sendCode(email, btn)
	}
	function forgotSubmit() {
	    let code = document.getElementById('forgotVerCode').value
		let email = document.getElementById('forgotEmail').value
		let pwd = document.getElementById('forgotPwd').value
		if(!code){
            showToast('please check Verification code')
            return false
		}
        if(!email || !checkEmail(email)) {
            showToast('please check Email')
            return false
        }
        if(!pwd || pwd.length < 6) {
            showToast('please check Password')
            return false
        }
        showLoading()
	    _axios.put('/v1/user/rest/pwd', {
	        code:code,
            email: email,
            newPassword: pwd
	    }).then(res => {
		    if(res.Code === 200){
				login(email, pwd)
		    } else {
		        hideLoading()
			    showToast(res.Msg)
		    }
	    })
	}
</script>